import java.lang.reflect.Array;
import java.util.Arrays;

public class MainTanxin {
    public static void main(String[] args) {
        //TIP 当文本光标位于高亮显示的文本处时按 <shortcut actionId="ShowIntentionActions"/>
        // 查看 IntelliJ IDEA 建议如何修正。
        System.out.printf("Hello and welcome!");

        for (int i = 1; i <= 5; i++) {
            //TIP 按 <shortcut actionId="Debug"/> 开始调试代码。我们已经设置了一个 <icon src="AllIcons.Debugger.Db_set_breakpoint"/> 断点
            // 但您始终可以通过按 <shortcut actionId="ToggleLineBreakpoint"/> 添加更多断点。
            System.out.println("i = " + i);
        }
    }
}

class Solution1 {
    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        if (s.length < 1)
            return 0;
        int count = 0;
        int j = 0, i = 0;
        while (i < s.length && j < g.length) {
            if (g[j] <= s[i]) {
                count++;
                j++;
            }
            i++;
        }
        return count;

    }
}

//class Solution {
//    public int wiggleMaxLength(int[] nums) {
//        if (nums.length == 1)
//            return 1;
//        if (nums.length == 2 && nums[0] - nums[1] != 0)
//            return 2;
//        else if (nums.length == 2 && nums[0] - nums[1] == 0) {
//            return 1;
//        }
//        int comp = 0;
//        int max = 1;
//        int length = 1;
//        for (int i = 1; i < nums.length; i++) {
//
//            if (nums[i] - nums[i - 1] > 0 && comp != 1) {
//                comp = 1;
//                length++;
//            } else if (nums[i] - nums[i - 1] < 0 && comp != 2) {
//                comp = 2;
//                length++;
//            }
//
//            if(length>max)
//                max=length;
//        }
//    return max;
//
//    }
//}
class Solution2 {
    public int wiggleMaxLength(int[] nums) {
        if (nums.length < 2) return nums.length;

        int comp = 0;  // 0: undefined, 1: up, 2: down
        int length = 1;

        for (int i = 1; i < nums.length; i++) {
            int diff = nums[i] - nums[i - 1];
            if (diff > 0 && comp != 1) {
                comp = 1;
                length++;
            } else if (diff < 0 && comp != 2) {
                comp = 2;
                length++;
            }
        }

        return length;
    }
}

class Solution3 {
    public int maxSubArray(int[] nums) {
        int sum=nums[0];
        int max = nums[0];
        int start=0,end = 0;
        for(int i=1;i<nums.length;i++){
            if(nums[i]+sum<nums[i]){
                sum=nums[i];
                start=i;
            }else{
                sum+=nums[i];
            }
            if(sum>max){
                max=sum;
                end = i;
            }
        }
        System.out.println(start+" "+end);
        return max;
    }
}

class Solution4 {
    public int maxProfit(int[] prices) {
        int sum = 0;
        for (int i = 1;i<prices.length;i++){
            if(prices[i]-prices[i-1]>0)
                sum += prices[i]-prices[i-1];
        }
        return sum;
    }
}

//class Solution {
//    public boolean canJump(int[] nums) {
//        if (nums.length == 1)
//            return true;
//        int cover = 1;
//        for (int i = 0; i < cover; i++) {
//            if (i + nums[i]+1 > cover)
//                cover = i + nums[i]+1;
//            if (i + nums[i] +1>= nums.length) {
//                return true;
//            }
//
//        }
//        return false;
//    }
//}
class Solution5 {
    public boolean canJump(int[] nums) {
        if(nums.length==1)
            return true;
        int cover = 1;
        for(int i=0;i<cover;i++){
            int j = nums[i]+i;
            int s=i+1;
            while(s<j+1){
                if(s+nums[s]>cover)
                    cover = s+nums[s];
                if(s+nums[s]>=nums.length-1){
                    return true;
                }
                s++;
            }

        }
        return false;
    }
}

class Solution {
    public int jump(int[] nums) {
        for(int i = 0;i<nums.length;i++){
            int j = nums[i]+1;
            int s = i+1;
        }
    }
}